Fix submodules on the initial checkout
authorAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 05:26:38 +0000 (22:26 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 05:26:38 +0000 (22:26 -0700)
The fast path bypassed updating the submodule which wasn't correct if we were
the first checkout.

src/cargo/sources/git/utils.rs
tests/test_cargo_compile_git_deps.rs

index 4caab78801ddc854728b166c994d5d45499a995d..8e4cdadd4497b46147ec3aa5de23b58172c2541d 100644 (file)
@@ -195,11 +195,10 @@ impl GitDatabase {
                                                     rev.clone()));
 
         match self.remote.rev_for(dest, "HEAD") {
-            Ok(ref head) if rev == *head => return Ok(checkout),
+            Ok(ref head) if rev == *head => {}
             _ => try!(checkout.fetch()),
         }
 
-        try!(checkout.reset());
         try!(checkout.update_submodules());
 
         Ok(checkout)
@@ -284,6 +283,7 @@ impl GitCheckout {
         // In this case we just use `origin` here instead of the database path.
         git!(self.location, "fetch", "--force", "--quiet", "origin");
         git!(self.location, "fetch", "--force", "--quiet", "--tags", "origin");
+        try!(self.reset());
         Ok(())
     }
 
index 0aea6702cc5c6d66b2669d049e81145ced977ddc..26c419bbe3a2fcdea6798a97bd012ece8bbdaab6 100644 (file)
@@ -674,3 +674,56 @@ test!(update_with_shared_deps {
                     git = git_project.root().display(),
                     compiling = COMPILING, dir = p.root().display())));
 })
+
+test!(dep_with_submodule {
+    let project = project("foo");
+    let git_project = git_repo("dep1", |project| {
+        project
+            .file("Cargo.toml", r#"
+                [package]
+                name = "dep1"
+                version = "0.5.0"
+                authors = ["carlhuda@example.com"]
+            "#)
+    }).assert();
+    let git_project2 = git_repo("dep2", |project| {
+        project
+            .file("lib.rs", "pub fn dep() {}")
+    }).assert();
+
+    git_project.process("git").args(["submodule", "add"])
+               .arg(git_project2.root()).arg("src").exec_with_output().assert();
+    git_project.process("git").args(["add", "."]).exec_with_output().assert();
+    git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
+               .assert();
+
+    let project = project
+        .file("Cargo.toml", format!(r#"
+            [project]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.dep1]
+
+            git = 'file:{}'
+        "#, git_project.root().display()))
+        .file("src/lib.rs", "
+            extern crate dep1;
+            pub fn foo() { dep1::dep() }
+        ");
+
+    let root = project.root();
+    let git_root = git_project.root();
+
+    assert_that(project.cargo_process("cargo-build"),
+        execs()
+        .with_stdout(format!("{} git repository `file:{}`\n\
+                              {} dep1 v0.5.0 (file:{}#[..])\n\
+                              {} foo v0.5.0 (file:{})\n",
+                             UPDATING, git_root.display(),
+                             COMPILING, git_root.display(),
+                             COMPILING, root.display()))
+        .with_stderr(""));
+})